package com.spic.system.controller;

import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.system.domain.UserAll;
import com.spic.system.service.BusinessDataScopeService;
import com.spic.system.service.IHrService;
import com.spic.system.service.impl.UserAllService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : 赵祥
 * create at:  2022/11/14  15:21
 * @Description :
 **/
@Slf4j
@RestController
@RequestMapping("/userall")
public class UserAllController extends BaseController {
    @Autowired
    private UserAllService userAllService;
    @Autowired
    private IHrService hrService;
    @Autowired
    private BusinessDataScopeService businessDataScopeDBService;
    @GetMapping("/list")
    public TableDataInfo list(UserAll userAll)
    {
        //获取部门及子部门
        if (null != userAll.getDeptId()){
            List<Long> deptIds = businessDataScopeDBService.deptAndChildrenIds(userAll.getDeptId());
            userAll.setDeptIds(deptIds);
        }

        startPage();
        List<UserAll> list = userAllService.selectUserAllList(userAll);
        return getDataTable(list);
    }

    /**
     * 同步 sys_user及hr_user表的数据到 user_all
     * @return
     */
    @GetMapping("/syncuser2all")
    public AjaxResult syncUser2All() {
        userAllService.syncUser2All();
        hrService.syncHrUser2All();
        return AjaxResult.success();
    }

    @GetMapping("filterDirtyData")
    public AjaxResult filterDirtyData() {
        userAllService.filterDirtyData();
        return AjaxResult.success();
    }
}
